package com.mayuhao.departmentmanage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mayuhao.departmentmanage.entity.Department;
import com.mayuhao.departmentmanage.service.IDepartmentService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


/**
 * @author 马宇豪
 * @PackageName course-selection-system
 * @Package com.mayuhao.departmentmanage.controller
 * @date 2022/10/19 周三下午 5:18:45
 * @email 1757442521@qq.com
 */

@RestController
//@RequestMapping("/department")
public class DepartmentController {
    @Resource
    private IDepartmentService departmentService;


    /**
     * @return boolean
     * @description 增加部门
     * @methodName saveDepartment
     * @params [department]
     * @paramType [com.mayuhao.departmentmanage.entity.Department]
     * @author 马宇豪
     * @date 2022/10/20 0020 下午 3:40
     * @email 1757442521@qq.com
     **/
    @PostMapping("/save")
    public boolean saveDepartment(@RequestBody Department department) {

        return departmentService.save(department);
    }

    /**
     * @return boolean
     * @description 删除部门
     * @methodName deleteDepartment
     * @params [id]
     * @paramType [java.lang.String]
     * @author 马宇豪
     * @date 2022/10/20 0020 下午 3:50
     * @email 1757442521@qq.com
     **/
    @DeleteMapping("/delsingle/{id}")
    public boolean deleteDepartment(@PathVariable Integer id) {
        return departmentService.removeById(id);
    }

    /**
     * @return boolean
     * @description 批量删除部门
     * @methodName deleteDepartment
     * @params [ids]
     * @paramType [java.util.List<java.lang.Integer>]
     * @author 马宇豪
     * @date 2022/10/22 0022 下午 2:01
     * @email 1757442521@qq.com
     **/
    @DeleteMapping("/delbatch/{ids}")
    public boolean deleteDepartment(@PathVariable List ids) {
        return departmentService.removeBatchByIds(ids);
    }

    /**
     * @return boolean
     * @description 修改部门
     * @methodName updateDepartment
     * @params [department]
     * @paramType [com.mayuhao.departmentmanage.entity.Department]
     * @author 马宇豪
     * @date 2022/10/20 0020 下午 4:10
     * @email 1757442521@qq.com
     **/
    @PutMapping("/update")
    public boolean updateDepartment(@RequestBody Department department) {
        return departmentService.updateById(department);
    }

    /**
     * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.mayuhao.departmentmanage.entity.Department>
     * @description 查询部门分页
     * @methodName findPage
     * @params [pageNum, pageSize, search]
     * @paramType [java.lang.Integer, java.lang.Integer, java.lang.String]
     * @author 马宇豪
     * @date 2022/10/20 0020 下午 5:10
     * @email 1757442521@qq.com
     **/
    @GetMapping("/findpage")
    public Page<Department> findPage(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "7") Integer pageSize, @RequestParam(defaultValue = "") String searchId, @RequestParam(defaultValue = "") String searchName) {
        return departmentService.findPage(pageNum, pageSize, searchId, searchName);
    }

    /**
     * @return void
     * @description 文件导出
     * @methodName export
     * @params [response]
     * @paramType [javax.servlet.http.HttpServletResponse]
     * @author 马宇豪
     * @date 2022/10/22 0022 下午 3:24
     * @email 1757442521@qq.com
     **/
    @GetMapping("/export")
    public void export(HttpServletResponse response) throws IOException {

        departmentService.export(response);
    }

    @PostMapping("/import")
    public void imp(MultipartFile file) throws Exception {

        departmentService.imp(file);
    }


}
